package com.shunde.xunjian.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.gson.Gson;
import com.shunde.xunjian.entity.ComplaintRegistration;
import com.shunde.xunjian.entity.VerificationReport;
import com.shunde.xunjian.mapper.dbnetworkshunde.ComplaintRegistrationMapper;
import com.shunde.xunjian.mapper.dbnetworkshunde.VerificationReportMapper;
import com.shunde.xunjian.util.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class VerificationReportServiceImpl {

    @Autowired
    private VerificationReportMapper verificationReportMapper;

    @Autowired
    private ComplaintRegistrationMapper complaintRegistrationMapper;

    public Object VerificationReportResults(String verificationReportStr, Integer current, Integer pageSize) {
        VerificationReport verificationReport = new Gson().fromJson(verificationReportStr, VerificationReport.class);
        QueryWrapper<VerificationReport> verificationReportQueryWrapper = new QueryWrapper<>();
        IPage<VerificationReport> page = new Page<>(current, pageSize);
        if (verificationReportStr != null) {
            if (verificationReport.getVerificationId() != null) {
                verificationReportQueryWrapper.eq("verification_id", verificationReport.getVerificationId());
            }
            if (verificationReport.getComplaintId() != null) {
                verificationReportQueryWrapper.eq("complaint_id", verificationReport.getComplaintId());
            }
        }
        IPage<VerificationReport> reportOrdersIPage = verificationReportMapper.selectPage(page, verificationReportQueryWrapper);
        return reportOrdersIPage;
    }

    public Integer VerificationUpload(String verificationReportStr) {
        VerificationReport verificationReport = new Gson().fromJson(verificationReportStr, VerificationReport.class);
        Integer result = 0;
        if (!Utils.isEntityEmpty(verificationReport)) {
            ComplaintRegistration complaintRegistration = new ComplaintRegistration();
            complaintRegistration.setComplaintId(Integer.valueOf(verificationReport.getComplaintId()));
            complaintRegistration.setReviewStatus("已核查");
            complaintRegistrationMapper.updateById(complaintRegistration);
            result = verificationReportMapper.insert(verificationReport);
        }
        return result;
    }



}
